package com.dongdongshop.Email;

import com.dongdongshop.pojo.ToEmail;
import com.dongdongshop.service.UserService;
import com.dongdongshop.shiroutil.ShiroUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

//发送邮件
@Controller
public class EmailController {
    @Autowired
    private SendMailService sendMailService;

    @DubboReference
    private UserService userService;


    //发送普通邮件
    @RequestMapping("sendmail")
    @ResponseBody
    public String sendMail (String username){

        String pwd="123456";
        String salt = ShiroUtils.generateSalt(6);//盐
        String md5 = ShiroUtils.encryptPassword("MD5", pwd, salt, 3);
        userService.updatepwd(username,md5);

        ToEmail te=new ToEmail();
        String[] str = {"2645874117@qq.com"};//接收者
        te.setTos(str);
        te.setContent(pwd);//呢绒
        te.setSubject("你好");//标题

        try {
            sendMailService.sendMail(te);
            return "ok";
        }catch (Exception e){
            e.printStackTrace();
            return "no";
        }
    }
}
